package web.suzy.oj.manager.admin.discussion;

import com.baomidou.mybatisplus.core.metadata.IPage;
import lombok.extern.slf4j.Slf4j;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import web.suzy.oj.common.exception.StatusFailException;
import web.suzy.oj.common.result.ResultBean;
import web.suzy.oj.dao.discussion.DiscussionEntityService;
import web.suzy.oj.dao.discussion.DiscussionReportEntityService;
import web.suzy.oj.pojo.entity.discussion.Discussion;
import web.suzy.oj.pojo.entity.discussion.DiscussionReport;
import web.suzy.oj.pojo.vo.DiscussionReportVO;
import web.suzy.oj.shiro.AccountProfile;

import java.util.List;

/**
 * YangSuzy 软件工作室
 * 类名: AdminDiscussionManager
 * 描述: ---- 待定 -----
 * 功能: ---- 待定 -----
 *
 * @author YangSuzy
 * Date: 2022/11/29 13:23
 */
@Component
@Slf4j(topic = "suzyoj")
public class AdminDiscussionManager {
    @Autowired
    private DiscussionEntityService discussionEntityService;

    @Autowired
    private DiscussionReportEntityService discussionReportEntityService;

    /**
     * 方法名: removeDiscussion
     * 描述: 删除讨论
     *
     * @param didList 讨论ID列表
     * @return void
     * @date 2022/11/29 13:24
     * @auther YangSuzy
     **/
    public void removeDiscussion(List<Integer> didList) throws StatusFailException {
        boolean isOk = discussionEntityService.removeByIds(didList);
        if (!isOk) {
            throw new StatusFailException("删除失败");
        }
        AccountProfile userRolesVo = (AccountProfile) SecurityUtils.getSubject().getPrincipal();
        log.info("[{}],[{}],didList:[{}],operatorUid:[{}],operatorUsername:[{}]",
                "Admin_Discussion", "Delete", didList, userRolesVo.getUid(), userRolesVo.getUsername());
    }

    /**
     * 方法名: updateDiscussion
     * 描述: 更新讨论
     *
     * @param discussion 讨论
     * @return void
     * @date 2022/11/29 13:54
     * @auther YangSuzy
     **/
    public void updateDiscussion(Discussion discussion) throws StatusFailException {
        boolean isOk = discussionEntityService.updateById(discussion);
        if (!isOk) {
            throw new StatusFailException("修改失败");
        }
    }

    /**
     * 方法名: getDiscussionReport
     * 描述: 获取讨论举报信息
     *
     * @param limit       每页显示数目
     * @param currentPage 当前页
     * @return com.baomidou.mybatisplus.core.metadata.IPage<web.suzy.oj.pojo.vo.DiscussionReportVO>
     * @date 2022/11/29 13:49
     * @auther YangSuzy
     **/
    public IPage<DiscussionReportVO> getDiscussionReport(Integer limit, Integer currentPage) {
        return discussionReportEntityService.getDiscussionReportList(limit, currentPage);
    }

    /**
     * 方法名: updateDiscussionReport
     * 描述: 更新讨论举报信息
     *
     * @param discussionReport 举报信息
     * @return void
     * @date 2022/11/29 13:59
     * @auther YangSuzy
     **/
    public void updateDiscussionReport(DiscussionReport discussionReport) throws StatusFailException {
        boolean isOk = discussionReportEntityService.updateById(discussionReport);
        if (!isOk) {
            throw new StatusFailException("修改失败");
        }
    }
}
